/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-09-23
 * Time: 17:42
 */
public class findPoisoned_Duration {
    /**
     * @param timeSeries 被攻击时间
     * @param duration   中毒持续时间
     * @return 总中毒时间
     */
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int ret = 0;
        for (int i = 0; i < timeSeries.length - 1; i++) {
            int dur = timeSeries[i + 1] - timeSeries[i];
            if (dur >= duration) {
                ret += duration;
            } else {
                ret += dur;
            }
        }

        return ret + duration;
    }
}
